<template>
    <el-form ref="form" :model="form" label-width="100px">
                <el-form-item label="头像">
                
                  <el-upload
                  class="avatar-uploader"
                  action="/api/consumerUpload"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload">
                  <img v-if="head_portrait" :src="head_portrait" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload> 
                </el-form-item>
               <el-form-item label="用户总数">
                  <!-- <el-input v-model="count "></el-input> -->
                  {{usercount}}
                </el-form-item> 
                <el-form-item label="订单总数">
                  <!-- <el-input v-model="count "></el-input> -->
                  {{ordercount}}
                </el-form-item> 
    </el-form>
</template>

<script>
    export default {
       created(){
           this.userscount()
           this.orderscount()
       },
        data() {
            return {
              head_portrait:'',
              usercount:'',
              ordercount:'',
            }
        },
       
        methods: {
            handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
        this.form.imageUrl=res;
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === '.jpg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      userscount(){
          const _this=this
           axios({
               url:'http://39.99.160.25:8088/users/web/count',
               method:'get'
           })
           .then(function(res){
               _this.usercount=res.data.data.count.user
           })
      },
      orderscount(){
                const _this=this
                axios({
                            url:'http://39.99.160.25:8088/orders/wx/count_order',
                            method:'get'
                        })
                        .then(function(res){
                            _this.ordercount=res.data.data.count.orders
                    })
      }
       
        }
       
    }
</script>

